﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Shell.Structure
{
    public class Cast
    {
        /// <summary>
        /// F1-112
        /// F12 - 123
        /// 0 - 48
　　　  /// 1 - 49
        /// 9 - 57
        /// </summary>
        public int Key { get; private set; }
        public List<Condition> Conditions { get; private set; }

        public Cast(string key)
        {
            switch (key)
            {
                case "0":
                    Key = 48;
                    break;
                case "1":
                    Key = 49;
                    break;
                case "2":
                    Key = 50;
                    break;
                case "3":
                    Key = 51;
                    break;
                case "4":
                    Key = 52;
                    break;
                case "5":
                    Key = 53;
                    break;
                case "6":
                    Key = 54;
                    break;
                case "7":
                    Key = 55;
                    break;
                case "8":
                    Key = 56;
                    break;
                case "9":
                    Key = 57;
                    break;
                case "F1":
                    Key = 112;
                    break;
                case "F2":
                    Key = 113;
                    break;
                case "F3":
                    Key = 114;
                    break;
                case "F4":
                    Key = 115;
                    break;
                case "F5":
                    Key = 116;
                    break;
                case "F6":
                    Key = 117;
                    break;
                case "F7":
                    Key = 118;
                    break;
                case "F8":
                    Key = 119;
                    break;
                case "F9":
                    Key = 120;
                    break;
                case "F10":
                    Key = 121;
                    break;
                case "F11":
                    Key = 122;
                    break;
                case "F12":
                    Key = 123;
                    break;
            }
            Conditions = new List<Condition>();
        }

        public bool IsPassed()
        {
            for (int i = 0; i < Conditions.Count; i++)
            {
                if (!Conditions[i].IsPassed())
                {
                    return false;
                }
            }
            return true;
        }

        public void Execute(IntPtr hWnd)
        {
            Console.WriteLine("press " + Key.ToString());
            APIUtil.PostMessage(hWnd, WndMessage.WM_KEYDOWN, (uint)Key, (uint)0);
            System.Threading.Thread.Sleep(10);
            APIUtil.PostMessage(hWnd, WndMessage.WM_KEYUP, (uint)Key, (uint)0);
        }
    }
}
